using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.DoctorDataInterf;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model.DataInterfaces.CRMDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Patient.Models;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class ConsultationController : Controller
    {
		private readonly IDoctorRepository doctorRepository;
		private readonly IPatientRepository patientRepository;
		private readonly IPatientTreatmentRepository patienttreatmentRepository;
		private readonly IInteractionRepository interactionRepository;
		private readonly IConsultationRepository consultationRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public ConsultationController()
        {
            doctorRepository = Registry.RepositoryFactory.GetDoctorRepository();
            patientRepository = Registry.RepositoryFactory.GetPatientRepository();
            patienttreatmentRepository = Registry.RepositoryFactory.GetPatientTreatmentRepository();
            interactionRepository = Registry.RepositoryFactory.GetInteractionRepository();
            consultationRepository = Registry.RepositoryFactory.GetConsultationRepository();
        }

        public ConsultationController(IDoctorRepository doctorRepository, IPatientRepository patientRepository, IPatientTreatmentRepository patienttreatmentRepository, IInteractionRepository interactionRepository, IConsultationRepository consultationRepository)
        {
			this.doctorRepository = doctorRepository;
			this.patientRepository = patientRepository;
			this.patienttreatmentRepository = patienttreatmentRepository;
			this.interactionRepository = interactionRepository;
			this.consultationRepository = consultationRepository;
        }

        //
        // GET: /Consultation/

        public ViewResult Index()
        {
            //return View(consultationRepository.AllIncluding(consultation => consultation.Doctor, consultation => consultation.Patient, consultation => consultation.Treatment, consultation => consultation.Interaction));
            return View(consultationRepository.All);
        }

        //
        // GET: /Consultation/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(consultationRepository.Find(id));
        }

        //
        // GET: /Consultation/Create

        public ActionResult Create()
        {
			ViewBag.PossibleDoctors = doctorRepository.All;
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleTreatments = patienttreatmentRepository.All;
			ViewBag.PossibleInteractions = interactionRepository.All;
       
            return View();
        } 

        //
        // POST: /Consultation/Create

        [HttpPost]
        public ActionResult Create(Consultation consultation)
        {
            if (ModelState.IsValid) {
                consultationRepository.InsertOrUpdate(consultation);
                consultationRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleDoctors = doctorRepository.All;
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleTreatments = patienttreatmentRepository.All;
				ViewBag.PossibleInteractions = interactionRepository.All;
				return View();
			}
        }
        
        //
        // GET: /Consultation/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleDoctors = doctorRepository.All;
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleTreatments = patienttreatmentRepository.All;
			ViewBag.PossibleInteractions = interactionRepository.All;
             return View(consultationRepository.Find(id));
        }

        //
        // POST: /Consultation/Edit/5

        [HttpPost]
        public ActionResult Edit(Consultation consultation)
        {
            if (ModelState.IsValid) {
                consultationRepository.InsertOrUpdate(consultation);
                consultationRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleDoctors = doctorRepository.All;
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleTreatments = patienttreatmentRepository.All;
				ViewBag.PossibleInteractions = interactionRepository.All;
				return View();
			}
        }

        //
        // GET: /Consultation/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(consultationRepository.Find(id));
        }

        //
        // POST: /Consultation/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var consult = consultationRepository.Find(id);
            consultationRepository.Delete(consult);
            consultationRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

